<%@page
	import="org.springframework.web.context.request.RequestAttributes"%>
<%@page import="org.springframework.web.servlet.ModelAndView"%>
<%@page import="ar.com.sectorwine.controllers.EmpresasController"%>
<%@page import="org.springframework.ui.Model"%>
<%@ page session="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<jsp:include page="../cabecera_home.jsp"></jsp:include>

<div class="cuerpo" align="center">
	<br>
	<div class="marco_publicacion" align="left">

		<b class="publicacion_titulo">Stocks - Listado</b> <br>
		<hr>

		<%
			try {
		%>
		<form:form method="post" modelAttribute="mis_stocks">
			<div class="tablas_busqueda" align="left">
				<table>
					<caption>Resultados de la Busqueda</caption>
					<thead>
						<tr>
							<th scope="col">Variedad</th>
							<th scope="col">Cantidad</th>
							<th scope="col">Creado</th>
							<th scope="col">Vencimiento</th>
							<th scope="col">Estado</th>
							<th scope="col">Interesados</th>
							<th scope="col">Detalles</th>
						</tr>
					</thead>
					<tfoot>
						<th scope="row">Total</th>
						<td colspan="6">${mis_stocks.size()} resultados</td>
					</tfoot>
					<tbody>
						<c:forEach items="${mis_stocks}" var="stocks">
							<tr>
								<th scope="row">${stocks.variedad}</th>
								<td scope="row">${stocks.cantidad}</td>
								<td scope="row"><fmt:formatDate
										value="${stocks.fechaCreacionStock}" pattern="MM/dd/yyyy"
										timeZone="GMT" /></td>
								<td scope="row"><fmt:formatDate
										value="${stocks.vencimiento}" pattern="MM/dd/yyyy"
										timeZone="GMT" /></td>
								<c:choose>
									<c:when test='${stocks.fechaVenta != null}'>
										<td scope="row"><span style="color: red;">Vendido</span></td>
									</c:when>

									<c:otherwise>
										<td scope="row"><span style="color: green;">Disponible</span></td>
									</c:otherwise>
								</c:choose>
								<c:set var="isSelected" value="false" scope="page" />
								<c:forEach items="${interesados}" var="interes">
									<c:choose>
										<c:when test="${!isSelected}">
											<c:choose>
												<c:when test='${stocks.id == interes.stock.id}'>
													<td scope="row" align="center">${interes.contadorAccesos}</td>
													<c:set var="isSelected" value="true" scope="page" />
												</c:when>
												<c:otherwise>
													<td scope="row" align="center">0</td>
												</c:otherwise>
											</c:choose>
										</c:when>
										<c:otherwise>
											<td scope="row" align="center">0</td>
										</c:otherwise>
									</c:choose>
								</c:forEach>
								<td scope="row"><a href="stocks_detalle?id=${stocks.id}">VER</a></td>
							</tr>

						</c:forEach>
					</tbody>
				</table>
			</div>
		</form:form>

		<%
			} catch (Exception e) {
				out.print(e.getMessage());
			}
		%>
	</div>

</div>

<jsp:include page="../pie_de_pagina_compartida.jsp"></jsp:include>
